<!--
* description: 网点不良品审核
* author: xuliwen
* createdDate: 2021-01-21
-->
<template>
  <div class="app-container app-container-table">
    <one-table-template
      ref="multipleTable"
      :key="oneTableKey"
      :dynamic-buttons="tableButtons"
      :dynamic-components="tableComponents"
      :dynamic-api-config="apiConfig"
      :dynamic-table-cols="tableCols"
      :dynamic-form-fields="formField"
      :dynamic-is-show-select="true"
      :dynamic-is-init-table="true"
      :dynamic-is-show-more-btn="true"
      :dynamic-api-style="'restful'"
      :callback-obj="callbackObj"
    />

    <edit
      :key="editPopupsKey"
      :popups-visible="editPopupsVisible"
      :selectiondata="selectiondata"
      :popups-state="editPopupsState"
      :dynamic-api-style="'restful'"
      @close="close"
    />
  </div>
</template>
<script>
import { oneTableWithViewTemplateMixins } from "@/components/mixins/oneTableWithViewTemplateMixins";
import OneTableTemplate from "@/components/templates/oneTable";
import api from "@/api/pa/apiBranchWarehouse";
import Vue from "vue";
import transferApi from "@/api/apiVeTransferManagement";

export default {
  name: "defectiveProductsVerify",

  components: {
    OneTableTemplate,
    Edit: () => import("./edit"),
  },
  // 组件混入对象
  mixins: [oneTableWithViewTemplateMixins],

  // 阻塞路由预加载网格中组件的数据
  beforeRouteEnter(to, from, next) {
    Vue.prototype.$ConfigCache.CacheConfig.initData([to.path, ""], function () {
      next();
    });
  },

  data() {
    // 页面标识（与上面beforeRouteEnter中的对应）
    const viewPageCode = this.$route.path;

    // 绑定事件配置化事件
    this.$ConfigCache.CacheConfig.bindEvent(this, [viewPageCode]);

    return {
      icon: "el-icon-arrow-down",
      status: false,
      editRowData: {},
      selectiondata: [],
      // 网格查询API配置对象
      apiConfig: api.queryUsable,
      // 动态组件-按钮
      tableButtons: [
        {
          compKey: "btnKey1",
          type: "primary",
          size: "small",
          name: "search",
          clickEvent: () => this.queryTable(1),
          text: this.$t("sys.button.query"), // 查询
          position: "right",
          fuzzySearch: true,
        },
        {
          compKey: "btnKey2",
          type: "",
          size: "small",
          name: "reset",
          clickEvent: () => this.reset(),
          text: this.$t("sys.button.reset"),
          position: "right", // 重置
        },
        // {
        //   compKey: 'btnKey3',
        //   type: '',
        //   size: 'small',
        //   name: 'add',
        //   clickEvent: this.add,
        //   text: this.$t('sys.button.add'), // 新增
        //   position: 'left'
        // },
        {
          compKey: "btnKey3",
          type: "",
          size: "small",

          parentFileds: "disabled:table",
          clickEvent: () => {
           if( !this.selectiondata.length){
             this.$message('请选择要通过的数据')
           }

            this.$confirm('确定要提交吗?', '提示', {
              type: 'warning'

            }).then(() => {
              // this.$requestAPI(this.$getParams({
              //   apiConfig: transferApi.moveVerifyAdopt,
              //   variables: this.selectList
              // })).then(response => {
              //   if (response.result === '0') {
              //     if (response.msg) {
              //       this.$message({ message: response.msg, type: 'warn', uration: 2000 })
              //     }
              //     return
              //   }
              //   this.$message({ message: response.msg, type: 'warn', uration: 2000 })
              //   this.selectList = []
              //   setTimeout(() => {
              //     this.queryTable(1)
              //   }, 2000)
              // }).catch(err => {
              //   console.info(err)
              // })
              const loading = this.$loading({ text: `请稍等...` })
              this.$requestAPI({
                apiUrl:'/mp/e3sh/spareparts/nodestorehouse/rejectsAdministrationService/updateApproved.do',
                variables: this.selectiondata


              }).then(res => {
                if(res.result === '1') {
                  this.selectiondata=[]

                  this.queryTable(1)
                } else {
                  this.$message(res.msg ? res.msg : '')
                }
              }).catch(err => {
                if (err.response.data.msg) {
                  this.$message(err.response.data.msg)
                } else {
                  this.$message(err.message)
                }
              }).finally(() => {
                loading.close()
              })
            })
          },
          text: '通过',
          position: 'left',
          name: "adopt",
        },

        {
          compKey: "btnKey4",
          disabled: true,
          parentFileds: "disabled:table",
          type: "",
          size: "small",
          clickEvent:this.edit,
          text: "驳回", // err
          name: "reject",
          position: "left",
        },
      ],

      // 动态组件-查询条件
      tableComponents:
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path] &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
          .tableComponents &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
          .tableComponents.length > 0
          ? this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
              .tableComponents
          : [
            {
                compKey: "compKey1",
                labelName: "仓库名称：",
                codeField: "warehouseId",
                component: () => import("@/components/org/commonSelect"),
                textField: "warehouseName",
                customObj: {
                  api: api.queryWarehouseNameSelect,
                  defOptionFields: ["warehouseId", "warehouseName"],
                },
                type: "dropdownList",
                isMul: false,
                isMust: true,
              },
             {
                compKey: "compKey2",
                labelName: "备件编码：",
                codeField: "partNo",
                component: () => import("@/components/org/commonInput"),
                type: "inputText",
                isMul: false,
                isMust: true,
              },
               {
                compKey: "compKey3",
                labelName: "备件名称：",
                codeField: "partName",
                component: () => import("@/components/org/commonInput"),
                type: "inputText",
                isMul: false,
                isMust: true,
              },
              //  {
              //   compKey: "compKey4",
              //   labelName: "审核状态：",
              //   codeField: "status",
              //   component: () => import("@/components/org/LookupValue"),
              //   oFields: "statusId,statusText",
              //   options: [
              //     { statusId: "0", statusText: "未提交" },
              //     { statusId: "1", statusText: "已提交" },
              //     { statusId: "2", statusText: "审核通过" },
              //     { statusId: "3", statusText: "审核驳回" },
              //     { statusId: "4", statusText: "作废" },
              //   ],
              //   type: "dropdownList",
              //   isMul: false,
              //   isMust: true,
              // },
            ],

         // 动态生成网格列
      tableCols:
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path] &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols
          .length > 0
          ? this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols
          : [
              {
                prop: "partId",
                label: "备件ID",
                hidden: true,
                alwaysHidden: true,
              },
              {
                prop: "storageId",
                label: "storageId",
                hidden: true,
                alwaysHidden: true,
              },

              {
                prop: "updateControlId",
                label: "并发控制ID",
                hidden: true,
                alwaysHidden: true,
              },
              {
                prop: "warehouseId",
                label: "仓库ID",
                hidden: true,
                alwaysHidden: true,
              },
              {
                prop: "warehouseName",
                label: "仓库名称",
                width: "150px",
              },
              {
                prop: "partNo",
                label: "备件编号",
              },
              {
                prop: "partName",
                label: "备件名称",
              },

              {
                prop: "accountQty",
                label: "账面库存",
              },
              {
                prop: "badProductsQty",
                label: "不良品",
              },
              {
                prop: "productsQtyAS",
                label: "良品",
              },
              {
                prop: "toAbleQtr",
                label: "不良品转良品",
              },
              {
                prop: "toUnableQty",
                label: "良品转不良品",
              },
              {
                prop: "remark",
                label: "备注",
              },
              {
                prop: "applyer",
                label: "登记人",
              },
              {
                prop: "applyDate",
                label: "登记时间",
                width: "150px",
              },
              {
                prop: "status",
                label: "状态",
              },
              {
                prop: "auditMark",
                label: "驳回原因",
              },
            ],
      callbackObj: {
        // 手动勾选时
        onCheckSelect: (selection, row) => {
          this.selectiondata = selection;
        },
        onCheckSelectChange: (selection) => {
          this.onCheckSelectChange1(selection);
          this.selectiondata = selection;
        },
      },
      // 表单查询数据
      formField: this.$utils.getFormField(
        this,
        {
          warehouseId: "",
          partName: "",
          status: "",
          partNo: "",
          status:["1"]
        },
        this.$ConfigCache.CacheConfig.cacheData[viewPageCode]
      ),
    };
  },
  mounted() {
    // 列表查询
    this.queryTable(1)

  },

  methods: {

    onCheckSelectChange1(selection) {
      var btn1 = this.tableButtons[2];
      var btn2 = this.tableButtons[3];
      const isCheck = selection && selection.length > 0;
      btn1.disabled = !isCheck;
      btn2.disabled = !isCheck;
    },
  },
};
</script>
<style lang='scss' scoped>
.red {
  background: red;
}
</style>
